import request from '@/utils/request';
import { AxiosPromise } from 'axios';
import { SysJobVO, SysJobForm, SysJobQuery } from '@/api/job/job/types';

/**
 * 查询SysJob信息列表
 * @param query
 * @returns {*}
 */

export const listSysJob = (query?: SysJobQuery): AxiosPromise<SysJobVO[]> => {
  return request({
    url: '/job/list',
    method: 'get',
    params: query
  });
};

/**
 * 查询SysJob信息详细
 * @param id
 */
export const getSysJob = (id: string | number): AxiosPromise<SysJobVO> => {
  return request({
    url: '/job/' + id,
    method: 'get'
  });
};

/**
 * api新增SysJob信息
 * @param data
 */
export const addSysJob = (data: SysJobForm) => {
  return request({
    url: '/job',
    method: 'post',
    data: data
  });
};

/**
 * 修改SysJob信息
 * @param data
 */
export const updateSysJob = (data: SysJobForm) => {
  return request({
    url: '/job',
    method: 'put',
    data: data
  });
};

/**
 * 删除SysJob信息
 * @param id
 */
export const delSysJob = (id: string | number | Array<string | number>) => {
  return request({
    url: '/job/' + id,
    method: 'delete'
  });
};

/**
 * 指定methodName特定的cron表达式
 * @param methodName
 * @param serviceName
 * @param serviceMethod
 */
export const getCronExpression = (methodName: string, serviceName: string, serviceMethod: string): AxiosPromise<string> => {
  return request({
    url: `/job/getCron/${methodName}/${serviceName}/${serviceMethod}`,
    method: 'get'
  });
};

/**
 * 停止指定任务
 * @param serviceName 服务名称
 * @param serviceMethod 服务方法
 */
export const stopTask = (serviceName: string, serviceMethod: string): AxiosPromise<string> => {
  return request({
    url: `/jobTask/stop/${serviceName}/${serviceMethod}`,
    method: 'delete'
  });
};

/**
 * 停止所有任务
 */
export const stopAllTasks = () => {
  return request({
    url: '/jobTask/stopAll',
    method: 'delete'
  });
};
